unit fLoginConfig;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OmniXml, OmniXmlConf;

type
  TfmLoginConfig = class(TForm)
    Label1: TLabel;
    edtServer: TEdit;
    Label2: TLabel;
    edtPort: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FConfFile: TXmlConf;
    procedure LoadConfig;
    procedure SaveConfig;
  public
    { Public declarations }
  end;

var
  fmLoginConfig: TfmLoginConfig;
const cClientConfigFile = 'config.xml';

implementation

{$R *.dfm}

procedure TfmLoginConfig.Button1Click(Sender: TObject);
begin
  SaveConfig;
  ModalResult := mrOk;
end;

procedure TfmLoginConfig.SaveConfig;
begin
  FConfFile.WriteString('system', 'host', edtServer.Text);
  FConfFile.WriteString('system', 'port', edtPort.Text);
end;

procedure TfmLoginConfig.LoadConfig;
begin
  edtServer.Text := FConfFile.ReadString('system', 'host', 'localhost');
  edtPort.Text := FConfFile.ReadString('system', 'port', '<default>');
end;

procedure TfmLoginConfig.FormCreate(Sender: TObject);
begin
  FConfFile := TXmlConf.Create(ExtractFilePath(Application.Exename)+cClientConfigFile);
  LoadConfig;
end;

procedure TfmLoginConfig.FormDestroy(Sender: TObject);
begin
  FConfFile.Free;
end;

end.
